package com.gzhryc.shared_device.pcl.core;

import com.gzhryc.common.logging.Logger;
import com.gzhryc.shared_device.pcl.core.decoders.GZXJ410Decoder;
import com.gzhryc.shared_device.pcl.core.decoders.GZXJ510Decoder;
import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.ConcurrentHashMap;

public class PwdDecodeFactory {

	final static Logger log = Logger.getLogger(PwdDecodeFactory.class);

	static ConcurrentHashMap<String, Decoder> Store = new ConcurrentHashMap<String, Decoder>();

	static {
		addDecoder(new GZXJ510Decoder());
		addDecoder(new GZXJ410Decoder());
	}

	public static void addDecoder(Decoder decoder) {
		Store.put(decoder.getKey(), decoder);
	}

	public static Decoder getDecoder(String key) {
		if (StringUtils.isNotBlank(key)) {
			Decoder decoder = Store.get(key);
			if (decoder == null) {
				log.error("未能获取" + key + "的密码解码器");
			}
			return decoder;
		}
		return null;
	}

	public static interface Decoder {

		public String getKey();

		public PwdResult getPwd(String deviceSn, String key, String indexStr, Integer times,Object extendData);
	}
}
